/*
 * NewJFrame.java
 *
 * Created on 20 gennaio 2008, 9.49
 */

import com.jsoft.linkbuild.listenerAndServerLibrary.*;
import com.jsoft.linkbuild.utility.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Hashtable;
import java.awt.event.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author  Inuyasha
 */
public class QuestionGame extends javax.swing.JFrame implements LinkBuildApp
{
    private int password;
    private QGameSessionRule qgsr;
    private MySimpleRule msr;
    private Hashtable nicks;
    private Hashtable users;
    private TimerQuestion tq;
    
    /** Creates new form NewJFrame */
    public QuestionGame(int password)
    {
        this.password = password;
        this.qgsr = new QGameSessionRule(this);
        this.msr = new MySimpleRule();
        this.nicks = new Hashtable<String,String>(); //IDUser, nick
        this.users = new Hashtable<String,String>(); //nick, IDUser
        this.tq = new TimerQuestion(this);
        
        RegistrationManager.getInstance().addRegistration(password, this.msr);
        SessionManager.getInstance().addSession(this.password, this.qgsr);
        initComponents();
        setVisible(true);
        this.tq.start();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setDefaultLookAndFeelDecorated(true);
        setTitle("Question Game!!!");
        setAlwaysOnTop(true);
        setResizable(false);

        jTextPane1.setEditable(false);
        jTextPane1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jTextPane1.setForeground(new java.awt.Color(0, 0, 255));
        jScrollPane1.setViewportView(jTextPane1);

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 204, 204), 5));

        jTextField1.setEditable(false);
        jTextField1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jTextField1.setForeground(new java.awt.Color(0, 153, 255));
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel2.setForeground(new java.awt.Color(255, 51, 51));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("PUNTI");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("0");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel6.setForeground(new java.awt.Color(255, 51, 51));
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 204, 204), 5));

        jTextField2.setEditable(false);
        jTextField2.setFont(new java.awt.Font("Tahoma", 1, 18));
        jTextField2.setForeground(new java.awt.Color(0, 153, 255));
        jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel3.setForeground(new java.awt.Color(255, 51, 51));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("PUNTI");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("0");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel7.setForeground(new java.awt.Color(255, 51, 51));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(40, 40, 40)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(57, 57, 57))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane2.setBackground(new java.awt.Color(0, 51, 204));
        jScrollPane2.setForeground(new java.awt.Color(255, 255, 255));

        jTextArea1.setBackground(new java.awt.Color(102, 102, 255));
        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jTextArea1.setForeground(new java.awt.Color(255, 255, 255));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED, new java.awt.Color(204, 204, 255), new java.awt.Color(204, 204, 255), new java.awt.Color(204, 204, 255), new java.awt.Color(204, 204, 255)));
        jScrollPane2.setViewportView(jTextArea1);
        jTextArea1.getAccessibleContext().setAccessibleName("jLabel1");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 741, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 741, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           
    
       
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration

    public int getPunti(String IDUser)
    {
        if(this.nicks.get(IDUser) == null) return 0;
            
        if(this.nicks.get(IDUser).equals(this.getGiocatore1()))
        {
            return Integer.parseInt(jLabel4.getText());
        }
        else if(this.nicks.get(IDUser).equals(this.getGiocatore2()))
        {
            return Integer.parseInt(jLabel5.getText());
        }
        else
            return 0;
    }
    
    public String getGiocatore1()
    {
        if(this.jLabel8 == null) return "";
        return this.jLabel8.getText();
    }
    
    public String getGiocatore2()
    {
        if(this.jLabel9 == null) return "";
        return this.jLabel9.getText();
    }
    
    public JTextArea getAppunti()
    {
        return this.jTextArea1;
    }
    
    public JLabel getDisplayTempo()
    {
        return this.jLabel1;
    }
    
    public JTextPane getDisplayDomanda()
    {
        return this.jTextPane1;
    }
    
    public boolean newUserRegistered(String IDUser)
    {
        return true;
    }

    public boolean userDisconnected(String IDUser)
    {
        if(this.nicks.get(IDUser).equals(jLabel8.getText()))
        {
            jLabel8.setText("");
            jLabel4.setText("0");
            jLabel6.setText("");
            jTextField1.setText("");
            //fare altre cose
            jTextArea1.append(this.nicks.get(IDUser)+" si e disconnesso!\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            return true;
        }
        else if(this.nicks.get(IDUser).equals(jLabel9.getText()))
        {
            jLabel9.setText("");
            jLabel5.setText("0");
            jLabel7.setText("");
            jTextField2.setText("");
            //fare altre cose
            jTextArea1.append(this.nicks.get(IDUser)+" si e disconnesso!\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            return true;
        }
        else
        {
            return false;
        }
    }

    public boolean userAbnormalDisconnected(String IDUser)
    {
        jTextArea1.append(this.nicks.get(IDUser)+" si e disconnesso in maniera anormale!\n");
        jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
        this.qgsr.saveLastPoints(IDUser);
        return userDisconnected(IDUser);
    }

    public boolean userDisconnectedForPing(String IDUser)
    {
        jTextArea1.append(this.nicks.get(IDUser)+" si e disconnesso per Ping Out!\n");
        jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
        this.qgsr.saveLastPoints(IDUser);
        return userDisconnected(IDUser);
    }

    public boolean userDisconnectedForSysBan(String IDUser, String message)
    {
        jTextArea1.append(this.nicks.get(IDUser)+" e stato bannato dal sistema!\n");
        jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
        this.qgsr.saveLastPoints(IDUser);
        return userDisconnected(IDUser);
    }

    public boolean userDisconnectedForAppBan(String IDUser, String message)
    {
        jTextArea1.append(this.nicks.get(IDUser)+" e stato bannato dall'applicazione!\n");
        jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
        this.qgsr.saveLastPoints(IDUser);
        return userDisconnected(IDUser);
    }

    //questo metodo e comunque invocato dopo del newUserRegistered.
    public boolean userRegistrationFields(String IDUser, String[] fields) 
    {
        if(jLabel8 == null || jLabel8.getText().equals(""))
        {
            jTextArea1.append("Benvenuto "+fields[0]+"\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            this.nicks.put(IDUser, fields[0]);
            this.users.put(fields[0], IDUser);
            jLabel8.setText(fields[0]);
            return true;
        }
        else if(jLabel9 == null || jLabel9.getText().equals(""))
        {
            jTextArea1.append("Benvenuto "+fields[0]+"\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            this.nicks.put(IDUser, fields[0]);
            this.users.put(fields[0], IDUser);
            jLabel9.setText(fields[0]);
            return true;
        }
        else
        {
            jTextArea1.append("Mi dispiace "+fields[0]+" ma il numero massimo di giocatori e stato raggiunto, ti devo disconnettere. \n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            ThreadManager.getInstance().requestForUserDisconnection(password, IDUser);
            return false;
        }
    }

    public boolean onClosing()
    {
        System.out.println("Faccio il dispose di QuestionGame");
        this.dispose();
        System.out.println("QuestionGame dispose eseguito");
        return true;
    }

    public boolean stringIncoming(String IDUser, String message)
    {
        if(this.tq.isQuestionActive() && this.tq.isCurrentlyReply(message))
        {
            this.tq.stop();
            if(this.nicks.get(IDUser).equals(this.getGiocatore1()))
            {
                try 
                {
                    jLabel6.setText("Corretto!!!");
                    Thread.sleep(3000);
                    jLabel6.setText("");
                    int punti = Integer.parseInt(jLabel4.getText())+this.tq.getPuntiAttuali();
                    jLabel4.setText(""+punti);
                    jTextField1.setText(message);
                    jTextArea1.append(this.getGiocatore1() + " HA VINTO LA MANCHE \n");
                    jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
                    Thread.sleep(6000);
                    jTextField1.setText("");
                    this.tq.start();
                } 
                catch (InterruptedException ex)
                {
                    Logger.getLogger(QuestionGame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else if(this.nicks.get(IDUser).equals(this.getGiocatore2()))
            {
                try 
                {
                    jLabel7.setText("Corretto!!!");
                    Thread.sleep(3000);
                    jLabel7.setText("");
                    int punti = Integer.parseInt(jLabel5.getText())+this.tq.getPuntiAttuali();
                    jLabel5.setText(""+punti);
                    jTextField2.setText(message);
                    jTextArea1.append(this.getGiocatore1() + " HA VINTO LA MANCHE \n");
                    jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
                    Thread.sleep(6000);
                    jTextField2.setText("");
                    this.tq.start();
                } 
                catch (InterruptedException ex)
                {
                    Logger.getLogger(QuestionGame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        else if(this.tq.isQuestionActive() && !this.tq.isCurrentlyReply(message))
        {
            if(this.nicks.get(IDUser).equals(this.getGiocatore1()))
            {
                try 
                {
                    jLabel6.setText("Sbagliato!!!");
                    Thread.sleep(3000);
                    jLabel6.setText("");
                } 
                catch (InterruptedException ex)
                {
                    Logger.getLogger(QuestionGame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else if(this.nicks.get(IDUser).equals(this.getGiocatore2()))
            {
                try 
                {
                    jLabel7.setText("Sbagliato!!!");
                    Thread.sleep(3000);
                    jLabel7.setText("");
                } 
                catch (InterruptedException ex)
                {
                    Logger.getLogger(QuestionGame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        return true;
    }

    public boolean stringArrayIncoming(String IDUser, String[] messages)
    {
        return false;
    }

    public boolean booleanIncoming(String IDUser, boolean message)
    {
        return false;
    }

    public boolean integerIncoming(String IDUser, int message)
    {
        return false;
    }

    public boolean byteIncoming(String IDUser, byte message)
    {
        return false;
    }

    public boolean charIncoming(String IDUser, char message) 
    {
        return false;
    }

    public boolean byteArrayIncoming(String IDUser, byte[] messages) 
    {
        return false;
    }

    public boolean logIncoming(String log)
    {
        return false;
    }

    //Viene chiamato sempre dopo del newUserRegistered ma prima di userRegistrationFields
    public boolean userSessionFields(String IDUser, Object[] fields)
    {
        int punti = this.qgsr.getLastPoints(IDUser);
        if(this.nicks.get(IDUser).equals(this.getGiocatore1()))
        {
            jLabel4.setText(""+punti);
            jTextArea1.append("Bentornato "+this.getGiocatore1()+" ho ripristinato i tuoi punti.\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            return true;
        }
        else if(this.nicks.get(IDUser).equals(this.getGiocatore2()))
        {
            jLabel5.setText(""+punti);
            jTextArea1.append("Bentornato "+this.getGiocatore2()+" ho ripristinato i tuoi punti.\n");
            jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
            return true;
        }
        else
            return false;
    }
}




